package com.xinz.activity;

import java.lang.reflect.Field;


import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class BaseActivity extends Activity {

	/**
	 * 屏幕宽度
	 */
	int screenWidth;
	/**
	 * 屏幕高度
	 */
	int screenHeight;
	/**
	 * 可布局高度
	 */
	int layoutableHeightPixel;
	/**
	 * 屏幕宽度（像素）
	 */
	int screenWidthPixel;
	/**
	 * 屏幕高度（像素）
	 */
	int screenHeightPixel;
	
	DisplayMetrics dm = new DisplayMetrics();
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		screenWidthPixel = dm.widthPixels;
		screenHeightPixel = dm.heightPixels;
		// 密度
		float density = dm.density;
		screenWidth = (int) (screenWidthPixel * density);
		screenHeight = (int) (screenHeightPixel * density);
		
		//隐去电池等图标和一切修饰部分（状态栏部分）
      	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      	// 隐去标题栏（程序的名字）
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		// 计算去除顶部label栏以外的剩余高度
		Class<?> clazz = null;  
		Object obj = null;  
		Field field = null;  
		int x = 0, sbar = 0;  
		try {  
		    clazz = Class.forName("com.android.internal.R$dimen");  
		    obj = clazz.newInstance();  
		    field = clazz.getField("status_bar_height");  
		    x = Integer.parseInt(field.get(obj).toString());  
		    sbar = this.getResources().getDimensionPixelSize(x);  
		    layoutableHeightPixel = screenHeightPixel - sbar;  
		} catch (Exception e) {  
		    e.printStackTrace();  
		} 
		
		Log.e("mediaPlayer", "screenWidth:" + screenWidth + " screenHeight:" + screenHeight + " layoutableHeight:" 
		+ layoutableHeightPixel + "\n"
		+ "screenWidthPixel:" + screenWidthPixel + " screenHeightPixel:" + screenHeightPixel);
		
	}
	
}
